package cn.smile.controller.core;

import cn.smile.bean.dto.core.DicInfoDTO;
import cn.smile.bean.dto.core.PickerDTO;
import cn.smile.bean.form.core.dic.DicAddForm;
import cn.smile.bean.form.core.dic.DicUpdateForm;
import cn.smile.bean.form.core.dic.QueryDicForm;
import cn.smile.business.core.IDicInfoService;
import cn.smile.commons.response.MyResult;
import com.baomidou.mybatisplus.core.metadata.IPage;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

import jakarta.annotation.Resource;

import java.util.List;

@RestController
@RequestMapping("api/dic")
public class DicController {

    @Resource
    private IDicInfoService service;

    @PostMapping(value = "addDic")
    public MyResult<Boolean> addDic(@Valid @RequestBody DicAddForm form) {
        return MyResult.OK(service.addDic(form));
    }

    @PostMapping(value = "updateDic")
    public MyResult<Boolean> updateDic(@Valid @RequestBody DicUpdateForm form) {
        return MyResult.OK(service.updateDic(form));
    }

    @GetMapping(value = "miniProjectDicList")
    public MyResult<List<PickerDTO>> miniProjectDicList(@RequestParam("parentId") String parentId) {
        return MyResult.OK(service.miniProjectDicList(parentId));
    }

    @PostMapping("query/page")
    public MyResult<IPage<DicInfoDTO>> queryPage(@RequestBody QueryDicForm form) {
        return MyResult.OK(service.queryPage(form));
    }

    @GetMapping(value = "delDic")
    public MyResult<Boolean> delDic(@RequestParam("dicId") String dicId){
        return MyResult.OK(service.delDic(dicId));
    }
}
